#pragma once
#include "Download_i.h"
#include "Thread.h"
#include <string>
#include <utility>
#include <map>
#include "DownloadThreadWorker.h"



class CThreadDownLoader 
	: public IThreadDownload	
	, public ICallerThread
{
public:
	CThreadDownLoader(void);
	~CThreadDownLoader(void);

	//IDownLoader
	virtual void AddEventHandler(IThreadDownloadEvent* pEventHandler) ;
	virtual void RemoveEventHandler(IThreadDownloadEvent* pEventHandler) ;
	virtual bool DownloadHTTP(DownLoadTaskID TaskID, const std::string& ip,const std::wstring& srcFile,const std::wstring& dstFile,bool isForceUpdate,bool isShow,INT64 from=-1);
	virtual INT64 CancleTask(DownLoadTaskID TaskID);
	virtual INT64 GetCurrentDownloadSize(DownLoadTaskID TaskID);
protected:

	//ICallerThread
	virtual void OnReceiveDataFromThread(UINT uMessage, WPARAM wParam, LPARAM lParam);

protected:	
	typedef std::pair <CThread*, CDownloadThreadWorker*> DownloadThreadPair;
	typedef std::map<DownLoadTaskID, DownloadThreadPair> DownLoadTaskID2DownloadThreadMap;	
	DownLoadTaskID2DownloadThreadMap m_mapDownloadThreads;
};
